package com.cskaoyan;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class DeleteJDBCDemo {

    public static void main(String[] args) throws SQLException {

        // 加载驱动
//        DriverManager.registerDriver(new Driver());

        // 获取连接
        String url = "jdbc:mysql://localhost:3306/35th_2?useSSL=false";
        String username = "root";
        String password = "123456";

        Connection connection = DriverManager.getConnection(url, username, password);


        // 获取一个Statement对象 , statement对象是用来执行SQL语句的
        Statement statement = connection.createStatement();


        // 执行SQL语句, 返回影响的行数
        String sql = "delete from city where id > 5";
        int affectedRows = statement.executeUpdate(sql);



        // 展示执行的结果
        System.out.println("affectedRows:" + affectedRows);

        // 关闭资源
        statement.close();
        connection.close();

    }
}
